<?php
namespace Index\Controller;
use Think\Controller;
header("Content-type: text/html; charset=utf-8");
class RegisterController extends Controller {
    public function RegisterAction(){
        // $this->show('你好，这是注册控制器模块','utf-8');
        // var_dump(I('POST.'));
        if (IS_POST) {
            //获取表单传过来的相应数据
            $username = I('post.user_name');
            $password = md5(I('post.password'));
            $email = I('post.email');
            $sex = I('post.sex');
            $job_id = I('post.job_id');
            $province= I('post.selectp');
            $city= I('post.selectc');
            $intruduce = I('post.intruduce');
            $seccode_verify = I('post.seccode_verify');
            $regist_time = date("Y-m-d H:i:s") ;
            // var_dump($login_time);
            // exit();
            //实例化M对象模型连接数据库表
            if($this->check_verify($seccode_verify)){
                $data_Object = M();
                $sql = "insert into user(username,truename,password,sex,jobs,province,introduce,regist_time) value('$username','$email','$password','$sex','$job_id','$province','$intruduce','$regist_time')";
                $res = $data_Object->execute($sql);
                 // var_dump($res);
                if($res){    //设置成功后跳转页面的地址，默认的返回页面是$_SERVER['HTTP_REFERER']    
                     $this->success('插入成功', U('index/login/login'),3);
                     // $this->success('操作完成','/Article/index',3);
                } else {    
                    //错误页面的默认跳转页面是返回前一页，通常不需要设置    
                     $this->error('用户名或密码错误');
                }
            }else{
                    $this->error('验证码输入错误');
            }
        }else{
             $this->display();
        }


       
    }

    public function codeAction(){
    	$config =    array(
    	'imageW'    =>    115,    // 验证码字体大小
    	'imageH'    =>    40,    // 验证码字体大小        
    	'fontSize'    =>    20,    // 验证码字体大小    
    	'length'      =>    3,     // 验证码位数    
    	'useNoise'    =>    false, // 关闭验证码杂点
    	);
    	$Verify =     new \Think\Verify($config);
    	$Verify->entry();
    }

    //验证码检测
    function check_verify($code, $id = ''){ 
       $verify = new \Think\Verify();  
       return  $verify->check($code, $id);
   }
}